/**
 * @(#) RegCheckProxy.as
 *
 * @date		2010. 11. 01
 * @version		2.0
 * @author		Shin, Yunwoo
 * @client		Service Ace 
 * @module		Compensation  (급여)
 * @description	주민번호 체크  - Proxy
 * 				
 */
package com.skt.common_hr.compensation.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.compensation.CompensationFacade;
	import com.wcl.dataloader.*;
	
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class RegCheckProxy extends CommonProxy
	{
		public static const NAME:String = "RegCheckProxy";
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function RegCheckProxy(data:Object=null)
		{
			super(NAME, data);
		}
		


		public var regNo:String;


		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;					// 사번
			param["I_R_CHECK"] = "I";					

			loadData("Z_HR_0012", param, loadResult, loadFault);
		}
		

		public function checkRegNo(pernr:String, regNo:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;					// 사번
			param["I_R_CHECK"] = "O";					// 사번
			param["I_C_REGNO"] = regNo;					// 사번

			loadData("Z_HR_0012", param, checkResult, checkFault);
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function loadResult(event:ResultEvent):void
		{
			if(retCode==0) {  
				regNo = event.result.F_REGNO.toString();
				facade.sendNotification(CompensationFacade.LOAD_REGNO_COMPLETE, this);
			}
			else {
				facade.sendNotification(CompensationFacade.LOAD_REGNO_FAILED, this);
			}
			CursorManager.removeBusyCursor();
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function loadFault(event:FaultEvent):void
		{
			facade.sendNotification(CompensationFacade.LOAD_REGNO_FAILED, this);
		}

		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function checkResult(event:ResultEvent):void
		{
			if(retCode==0) {  
				facade.sendNotification(CompensationFacade.VALID_REGNO, this);
			}
			else {
				facade.sendNotification(CompensationFacade.INVALID_REGNO, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function checkFault(event:FaultEvent):void
		{
			facade.sendNotification(CompensationFacade.INVALID_REGNO, this);
		}
		
	}
}